package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KAgeGroup;
import com.ruoyi.qsng.service.IKAgeGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 年龄段Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@Api(tags = "pc--年龄段Controller")
@RestController
@RequestMapping("/qsng/group")
public class KAgeGroupController extends BaseController {
    @Autowired
    private IKAgeGroupService kAgeGroupService;

    /**
     * 查询年龄段列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询年龄段列表")
    public TableDataInfo list(KAgeGroup kAgeGroup) {
        startPage();
        List<KAgeGroup> list = kAgeGroupService.selectKAgeGroupList(kAgeGroup);
        return getDataTable(list);
    }


    /**
     * 查询年龄段列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:list')")
    @GetMapping("/listNotLimit")
    @ApiOperation(value = "查询年龄段列表")
    public AjaxResult listNotLimit(KAgeGroup kAgeGroup) {
        List<KAgeGroup> list = kAgeGroupService.selectKAgeGroupList(kAgeGroup);
        return success(list);
    }

    /**
     * 导出年龄段列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:export')")
    @Log(title = "年龄段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出年龄段列表")
    public void export(HttpServletResponse response, KAgeGroup kAgeGroup) {
        List<KAgeGroup> list = kAgeGroupService.selectKAgeGroupList(kAgeGroup);
        ExcelUtil<KAgeGroup> util = new ExcelUtil<KAgeGroup>(KAgeGroup.class);
        util.exportExcel(response, list, "年龄段数据");
    }

    /**
     * 获取年龄段详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取年龄段详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kAgeGroupService.selectKAgeGroupById(id));
    }

    /**
     * 新增年龄段
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:add')")
    @Log(title = "年龄段", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增年龄段")
    public AjaxResult add(@RequestBody KAgeGroup kAgeGroup) {
        return toAjax(kAgeGroupService.insertKAgeGroup(kAgeGroup));
    }

    /**
     * 修改年龄段
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:edit')")
    @Log(title = "年龄段", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改年龄段")
    public AjaxResult edit(@RequestBody KAgeGroup kAgeGroup) {
        return toAjax(kAgeGroupService.updateKAgeGroup(kAgeGroup));
    }

    /**
     * 删除年龄段
     */
    @PreAuthorize("@ss.hasPermi('qsng:group:remove')")
    @Log(title = "年龄段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除年龄段")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kAgeGroupService.deleteKAgeGroupByIds(ids));
    }
}
